package cn.jhc.DaoImpl;

import javax.annotation.Resource;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository;

import cn.jhc.DAO.GoodsDao;
import cn.jhc.model.Goods;

@Repository
public class GoodDaoImpl implements GoodsDao{

	private SessionFactory sessionFactory;
	
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
   
	@Resource
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	@Override
	public void addGood(Goods goods) {
		Session session=sessionFactory.getCurrentSession();
		session.save(goods);
	}

	@Override
	public void removeGood(Integer id) {
		Session session=sessionFactory.getCurrentSession();
		session.delete(id);
	}

	@Override
	public Goods findGoodBybn(Integer id) {
		Session session=sessionFactory.getCurrentSession();
	    Goods goods = (Goods) session.get(Goods.class, id);
		return goods;
	}

	@Override
	public void updateGood(Goods goods) {
		Session session = sessionFactory.getCurrentSession();
		session.update(goods);
	}



	
}
